<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
 *  这个一个基类，方便扩展
 *  1、权限的验证，check_permission()
 *  2、检查登陆状态
*/
class MY_Controller extends CI_Controller {
  var $class_name;                 //当前类名
  var $method_name;                //当前调用方法
  var $init_invoke_results;        //初始化结果
  var $theme = 'default';          //主题
  var $images_url;                 //图片存放的url
  var $css_url;                    //css存放路径
  var $css_images_url;
  function __construct($funcs = array()) {
    parent::__construct();
    $this->init_vars();
    $this->init_invoke_results = $this->init_invoke($funcs);
  }

  public function init_vars() {
    $this->class_name = $this->router->class;
    $this->method_name = $this->router->method;
    $this->images_url = base_url().'theme/'.$this->theme.'/images/';
    $this->css_url = base_url().'theme/'.$this->theme.'/css/';
    $this->css_images_url = '../../theme/default/images/';
    
  }
  public function check_permission() {
    //print 'check_permission';
    return true;
  }

  public function check_login() {
    $name = $this->session->userdata('name');
    if (empty($name)) {
      return false;
    }
    else return true;
  }

  public function init_invoke($funcs = array()) {
    $rt = array();
    foreach ($funcs as $f) {
      if (!method_exists($this->class_name, $f)) show_error('controller <span style="color: red">'.$this->class_name.'</span> method <span style="color: red">'.$f.'</span> haven\'t exit!');
      //$result = call_user_func(array($this->class_name, $f));
      $result = $this->$f();
      $rt[$f] = $result;
      //call_user_func(array(get_class(), $f), $data);需要参数的话就直接加入$data即可
    }
    return $rt;
  }

}
// END MY_Controller class

/* End of file MY_Controller.php */
/* Location: ./application/core/MY_Controller.php */